package com.kinyx.framework.crawler;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.kinyx.framework.annotation.assist.CanNotNull;
import com.kinyx.framework.annotation.assist.ReturnNotNull;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
 * HTML工具类
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class KSoupUtils {

	/**
	 * 取当前元素内容（将内部所有HTML标签都移除）
	 * @param element 元素
	 * @return 内容
	 */
	@ReturnNotNull
	public static String html(@CanNotNull final Element element) {
		String html = element.html();
		final Elements children = element.children();
		if (!children.isEmpty()) {
			for (final Element child : children) {
				html = html.replace(child.outerHtml(), html(child));
			}
		}
		return html;
	}

}
